package com.ateam.dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;

import com.ateam.dao.CompaniesDao;
import com.ateam.pojo.Companies;

/** 
* @author WuYuan
* 
*/
public class CompaniesDaoImpl implements CompaniesDao {
	private SqlSessionTemplate sqlSessionTemplate;
	
	public SqlSessionTemplate getSqlSessionTemplate() {
		return sqlSessionTemplate;
	}

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}
	
	@Override
	public int addCompany(Companies company) throws Exception {
		return sqlSessionTemplate.insert("addCompany",company);
	}

	@Override
	public Companies getCompanyByUserid(int userid) throws Exception {
		return sqlSessionTemplate.selectOne("getCompanyByUserid",userid);
	}

	@Override
	public List<Companies> getAllCompanies() throws Exception {
		return sqlSessionTemplate.selectList("getAllCompanies");
	}

	@Override
	public int addUserCompany(int companyid, int userid, int adopt) throws Exception {
		Object[] objects = new Object[]{companyid, userid, adopt};
		return sqlSessionTemplate.insert("addUserCompany", objects);
	}

	@Override
	public int updateUserCompany(int companyid, int userid, int adopt) throws Exception {
		Object[] objects = new Object[]{companyid, userid, adopt};
		return sqlSessionTemplate.update("updateUserCompany", objects);
	}

}
